import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  {
    path: "/knowledge",
    name: "知识产权数据统计",
    component: Layout,
    meta: { title: "知识产权数据统计", icon: "el-icon-s-fold" },
    children: [
      {
        path: "index",
        name: "xxx",
        component: () => import("@/views/knowledge/index.vue"),
        meta: { title: "知识产权数据统计", icon: "el-icon-s-fold" },
      },
    ],
  },
  {
    path: "/companys",
    name: "合作公司数据统计",
    component: Layout,
    meta: { title: "合作公司数据统计", icon: "el-icon-menu" },
    children: [
      {
        path: "index",
        name: "公司",
        component: () => import("@/views/company/index.vue"),
        meta: { title: "公司", icon: "el-icon-s-fold" },
      },
    ],
  },
  {
    path: "/adminManage",
    component: Layout,
    redirect: "/adminManage/index",
    name: "adminManage",
    meta: { title: "角色管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "index",
        name: "角色权限树",
        component: () => import("@/views/adminManage/index"),
        meta: { title: "角色权限树", icon: "tree" },
      },
      {
        path: "roleTable",
        name: "roleTable",
        component: () => import("@/views/adminManage/home.vue"),
        meta: { title: "角色列表", icon: "table" },
      },
      {
        path: "adtiveTable",
        name: "adtiveTable",
        component: () => import("@/views/adminManage/adtiveTable.vue"),
        meta: { title: "功能列表", icon: "table" },
      },
    ],
  },
  {
    path: "/user",
    component: Layout,
    redirect: "/user/index",
    name: "user",
    meta: { title: "用户管理", icon: "el-icon-s-custom" },
    children: [
      {
        path: "index",
        name: "用户待审核列表",
        component: () => import("@/views/user/index"),
        meta: { title: "用户待审核列表", icon: "el-icon-s-fold" },
      },
      {
        path: "passUser",
        name: "用户审核失败列表",
        component: () => import("@/views/user/notUser.vue"),
        meta: { title: "用户审核失败列表", icon: "el-icon-s-fold" },
      },
      {
        path: "allUser",
        name: "用户列表",
        component: () => import("@/views/user/allUser.vue"),
        meta: { title: "用户列表", icon: "el-icon-s-fold" },
      },
    ],
  },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
